package com.c.ctgproject.adapter.review

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.entity.review.CarReviewEntity
import com.c.ctgproject.utils.handlerNull

/**
 *作者:LiBW
 *创建日期: 2020/9/12
 *描述: 报废车价格审核适配器
 */
class ReviewCarPriceAdapter(private val context: Context, private val mList: List<CarReviewEntity.DataBean.ListBean>, private val result: CarFragmentResult) : RecyclerView.Adapter<ReviewCarPriceAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_review_car_price_list, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data=mList[position]
        holder.mCarPlateTV.text=data.ownerPlate.handlerNull()
        holder.mTimeTV.text=data.createTime.handlerNull()
        holder.mCarOwnerTV.text=data.carOwner.handlerNull()
        holder.mCarPriceTV.text=data.applicationPrice.handlerNull()
        holder.mCarMarkTV.text=data.remark.handlerNull()

        //同意
        holder.mAgreeBTN.setOnClickListener {
            result.agree(data.applicationId)
        }
        //拒绝
        holder.mRefuseBTN.setOnClickListener {
            result.refuse(data.applicationId)
        }

    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val mCarPlateTV:TextView=itemView.findViewById(R.id.mOrderIdTV)
        val mTimeTV:TextView=itemView.findViewById(R.id.mTimeTV)
        val mCarOwnerTV:TextView=itemView.findViewById(R.id.mCarOwnerTV)
        val mCarPriceTV:TextView=itemView.findViewById(R.id.mCarPriceTV)
        val mCarMarkTV:TextView=itemView.findViewById(R.id.mCarMarkTV)
        val mAgreeBTN:TextView=itemView.findViewById(R.id.mAgreeBTN)
        val mRefuseBTN:TextView=itemView.findViewById(R.id.mRefuseBTN)
    }

    interface CarFragmentResult{
        fun agree(orderId:Int)
        fun refuse(orderId:Int)
    }
}